package kz.pompei.ifacer.cursor_manager.def;

import java.awt.Point;
import java.awt.Rectangle;

import kz.pompei.ifacer.model.CursorKind;
import kz.pompei.ifacer.model.widgets.WidgetRect;

public class DefRectGeo {
  public static CursorKind cursorKindOnBorder(Point mouse, WidgetRect w, int borderWidth,
      int cornerSize) {
    
    //
    // Corners
    //
    
    if (new Rectangle(w.x, w.y, cornerSize, cornerSize).contains(mouse)) {
      return CursorKind.RESIZE_NW;
    }
    if (new Rectangle(w.x + w.width - cornerSize, w.y, cornerSize, cornerSize).contains(mouse)) {
      return CursorKind.RESIZE_NE;
    }
    if (new Rectangle(w.x, w.y + w.height - cornerSize, cornerSize, cornerSize).contains(mouse)) {
      return CursorKind.RESIZE_SW;
    }
    if (new Rectangle(w.x + w.width - cornerSize, w.y + w.height - cornerSize, cornerSize,
        cornerSize).contains(mouse)) {
      return CursorKind.RESIZE_SE;
    }
    
    //
    // Sides
    //
    if (new Rectangle(w.x, w.y, w.width, borderWidth).contains(mouse)) {
      return CursorKind.RESIZE_N;
    }
    if (new Rectangle(w.x, w.y + w.height - borderWidth, w.width, borderWidth).contains(mouse)) {
      return CursorKind.RESIZE_S;
    }
    
    if (new Rectangle(w.x, w.y, borderWidth, w.height).contains(mouse)) {
      return CursorKind.RESIZE_W;
    }
    if (new Rectangle(w.x + w.width - borderWidth, w.y, borderWidth, w.height).contains(mouse)) {
      return CursorKind.RESIZE_E;
    }
    
    return null;
  }
  
}
